package com.planet.biz;

import com.planet.db.dao.HouseholdMapper;
import com.planet.db.model.Household;
import com.planet.facade.HouseholdBiz;
import com.planet.query.HouseholdQuery;
import com.planet.utils.CommonConverter;
import com.planet.vo.HouseholdVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jiayazi on 17/11/15.
 */
@Component("householdBiz")
public class HouseholdBizImpl implements HouseholdBiz{

    @Autowired
    HouseholdMapper householdMapper;

    @Override
    public HouseholdVO selectByPhone(String phone) {
        Household household = householdMapper.selectByPhone(phone);
        HouseholdVO householdVO = new HouseholdVO();
        CommonConverter.convert(household,householdVO);
        return householdVO;
    }

    @Override
    public boolean insertHost(HouseholdQuery householdQuery) {
        return householdMapper.insertHost(householdQuery);
    }

    @Override
    public List<HouseholdVO> getHostList() {
        List<Household> households = householdMapper.getHostList();
        List<HouseholdVO> householdVOS = new ArrayList<>(households.size());
        CommonConverter.convertList(HouseholdVO.class,households,householdVOS);
        return householdVOS;
    }
}
